import Websocket = require('ws');

class conn{
    private wsock: Websocket;
    private static instance: conn;
    public static getInstance(){
        if(!this.instance)
        {
            this.instance = new conn();
        }
        return this.instance;
    }
    private wsconn() {
        return new Promise((resolve) => {
            this.wsock = new Websocket('ws://localhost:13998');
            this.wsock.onopen = (e) =>{
                console.log('opened');
                resolve(1);
            }
            this.wsock.onerror = (e) => {
                console.log('error' + e.error);
                resolve(0);
            }
            this.wsock.onmessage = (e) => {
                console.log(`get: ${e.data}`);
                resolve(0);
            }
        })
        
    }
    public async sendData(){
        let a = await this.wsconn();
        this.wsock.send('no');
        console.log(a);
        
    }
}

let c = new conn();
c.sendData();

console.log(c)